atom

/avail/Avail/Foundation/Bootstrap/Special Objects: atom
Source: /avail/Avail/Foundation/Bootstrap/Special Objects
Categories: Primitives, Types, Atoms
Supertypes: nontype
An atom is a mutable value associated with a module-allocated name. For each name that appears in the Names section of a module's header, the compiler associates that name with a new atom. For each name that appears in the Uses or Extends section of a module's header, the compiler associates that name with the atom introduced by the module that named it. During compilation of a module, an atom may be retrieved by presenting its name, a string, to the primitive method atom for_. If the atom was neither introduced by the current module nor imported from another module, then atom for_ privately introduces a new atom into the current module; a subsequent send with the same argument within the context of the same module will produce the same atom.

In ordinary use, the primary asset of an atom is its distinction from every other value, including an equivalently named atom that originated in a different module. Consider the values true and false from classical logic. The principal characteristic of each is its distinction from the other. In other words, true and false differ by identity rather than by some measurable quantity. In Avail, the values true and false are special atoms; they are issued by the virtual machine rather than some module. The type boolean is simply the finite enumeration of these two atoms.

In addition to a name and an _'s⁇issuing module, an atom also comprises a collection of bindings, called properties. Since an atom has identity, it can acquire new properties, update existing properties, and lose properties altogether. A property is an association between another atom — the property key — and an arbitrary value — the property value. The properties of an atom are not enumerable, thus ensuring modular usage; an algorithm can only query or alter a property for which it possesses the key.

The type atom has every atom as an instance. atom is a complete type. Though its properties are analogous to the bindings of a map or the attributes of an object, atom does not require (or permit) type parameters for the property key type or the property value type. These limitations are a direct consequence of mutability.

Note that special atoms cannot participate in the property mechanism. For instance, the special atom true cannot be either the target or the property key of a property interrogation. It can be a property value, however.